package com.hellpro.lolbox.factory;

import android.support.v4.app.Fragment;
import android.util.SparseArray;

import com.hellpro.lolbox.acticity.view.CommandFragment;
import com.hellpro.lolbox.acticity.view.PrivacyFragment;

/**
 * 类描述:
 * 创建人:阿犇
 * 创建时间:2016/10/21
 * 备注:
 */

public class ContentRedFragmentFactory {

    private static final int RED_ONE = 0;
    private static final int RED_TWO = 1;

    //SparseArray:key是整形的key,根据整形的key来获取一个对象,效率比较高.
    private static SparseArray<Fragment> fragments = new SparseArray<>();

    //创建一个工厂方法,用来创建一个Fragment对象
    public static Fragment createFragment(int index) {
        //从集合中获取
        Fragment fragment = fragments.get(index);
        if (fragment == null) {
            switch (index) {
                case RED_ONE:
                    fragment = new CommandFragment();
                    break;
                case RED_TWO:
                    fragment = new PrivacyFragment();
                    break;
            }
            //存到集合中
            fragments.put(index, fragment);
        }

        return fragment;
    }
}
